﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZhouYu.DreamTour.BLL.IService;
using ZhouYu.DreamTour.DAL.IRepository;
using ZhouYu.DreamTour.Model;
using ZhouYu.DreamTour.ViewModel;

namespace ZhouYu.DreamTour.BLL.Service
{
    public class HotelService:IHotelService
    {
        private IHotelRepository _hotelRepository;
        public HotelService(IHotelRepository hotelRepository)
        {
            _hotelRepository = hotelRepository;
        }


        /// <summary>
        /// 获取酒店页面信息
        /// </summary>
        /// <returns></returns>
        public ResponseResult GetHotelsInfo()
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用获取酒店页面信息
            responseResult.data = _hotelRepository.GetHotelsInfo();
            return responseResult;
        }


        /// <summary>
        /// 获取酒店页面图片信息
        /// </summary>
        /// <returns></returns>
        public ResponseResult GetHotelsPicInfo()
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用获取酒店页面图片信息
            responseResult.data = _hotelRepository.GetHotelsPicInfo();
            return responseResult;
        }


        /// <summary>
        /// 根据Id获取酒店详情信息
        /// </summary>
        /// <returns></returns>
        public ResponseResult GetHotelDetailInfoById(int HotelId)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用根据Id获取酒店详情信息
            responseResult.data = _hotelRepository.GetHotelDetailInfoById(HotelId);
            return responseResult;
        }


        /// <summary>
        /// 获取酒店名称集合
        /// </summary>
        /// <returns></returns>
        public ResponseResult GetHotelNameList()
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用获取酒店名称集合
            responseResult.data = _hotelRepository.GetHotelNameList();
            return responseResult;
        }


        /// <summary>
        /// 根据酒店Id获取房间类型
        /// </summary>
        /// <returns></returns>
        public ResponseResult GetRoom_TypeByHotelId(int HotelId)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();
            //调用根据酒店Id获取房间类型
            responseResult.data = _hotelRepository.GetRoom_TypeByHotelId(HotelId);
            return responseResult;
        }

        /// <summary>
        /// 添加酒店预定信息
        /// </summary>
        /// <returns></returns>
        public ResponseResult AddHotelOrderInfo(HotelOrder hotelOrder,string Order_No)
        {
            //创建响应结果类对象
            ResponseResult responseResult = new ResponseResult();          
            //根据酒店Id查询酒店信息
            Hotel hotel = _hotelRepository.CheckInfoByHotelId(hotelOrder.HotelId);
            //根据酒店Id查询酒店图片
            HotelDetails hotelDetails = _hotelRepository.CheckHotelPicByHotelId(hotelOrder.HotelId);
            //根据房间Id获取房间价格
            RoomInfo roomInfo = _hotelRepository.GetRoom_PriceByRoom_Id(hotelOrder.Room_Id);
            //计算入住房间天数
            TimeSpan days=hotelOrder.OutTime - hotelOrder.IntoTime;
            int today =Convert.ToInt32(days.TotalDays);
            //创建订单对象
            OrderInfo orderInfo = new OrderInfo();
            //房间名称
            orderInfo.Order_ProInfo = hotel.HotelName;
            //入住时间
            orderInfo.Order_OutingTime = hotelOrder.IntoTime;
            //酒店图片
            orderInfo.Orde_PictureUrl = hotelDetails.Hotel_BigPic;
            //下单用户id
            orderInfo.User_Id = hotelOrder.User_Id;
            //订单金额
            orderInfo.Order_Money =roomInfo.Room_Price * today;
            //订单编号
            orderInfo.Order_No = Order_No;
            //下单备注
            orderInfo.Order_Content = hotelOrder.SpecialRequest;
            //调用添加酒店预定信息
            responseResult.Success = _hotelRepository.AddHotelOrderInfo(hotelOrder)>0;
            if (responseResult.Success)
            {
                //酒店预订成功同时调用添加酒店订单信息
                responseResult.data = _hotelRepository.AddOrderInfo(orderInfo);
            }
            return responseResult;
        }

        /// <summary>
        /// 根据酒店Id获取酒店名称
        /// </summary>
        /// <returns></returns>
        public string GetHotelName(int hotelId)
        {
            //调用根据酒店Id获取酒店名称
            return _hotelRepository.GetHotelName(hotelId);
        }       
    }
}
